Boost
boost
arrow_drop_down
Boost.Optional
C++ 11 Added in Boost 1.30.0
Categories: Data

A value-semantic, type-safe wrapper for representing 'optional' (or 'nullable') objects of a given type. An optional object may or may not contain a value of the underlying type.

This Release

Fernando Cacciola
Maintainer
Andrzej Krzemienski
Maintainer

optional

A library for representing optional (nullable) objects in C++.

optional<int> readInt(); // this function may return either an int or a not-an-int

if (optional<int> oi = readInt()) // did I get a real int
  cout << "my int is: " << *oi;   // use my int
else
  cout << "I have no int";

For more information refer to the documentation provided with this library.